layui.define(['form','table', 'element'], function(exports){
    var $ = layui.$,form = layui.form,table = layui.table, element = layui.element;

    var referrerUserId = $('input[name="referrerUserId"]').val();

    table.render({
        elem: '#LAY-table'
        ,url: layui.setter.webRoot + '/agent/referrer/user/list.data'
        ,where:{referrerUserId:referrerUserId}
        ,method: 'post'
        ,parseData: function (res) {
            return {
                "code": res.code,
                "msg": res.msg,
                "count": res.body.total,
                "data": res.body.data
            };
        }
        ,response: {statusCode: 200}
        ,cols: [[
			{field: 'userId', title: '用户ID'}
		    ,{field: 'name', title: '用户名称',templet:function (record){
		         return record.user.name;
		             }}
		    ,{field: 'phone', title: '用户手机号',templet:function (record){
		                 return record.user.phone;
		             }}
		    ,{field: 'nickname', title: '昵称',templet:function (record){
		                 return record.user.nickname;
		             }}
		  	,{field: 'typeNames', title: '代理类型'}
		    ,{field: 'levelName', title: '代理等级'}
		    ,{field: 'createDate', title: '创建时间'}
        ]]
        ,page: true
        ,height: 'full-220'
        ,text: '对不起，加载出现异常！'
    });
	
	table.render({
       elem: '#LAY-table-profit-cfg'
       ,url: layui.setter.webRoot + '/agent/referrer/profit/list.data'
       ,where:{referrerUserId:referrerUserId}
       ,method: 'post'
       ,parseData: function (res) {
           return {
               "code": res.code,
               "msg": res.msg,
               "count": res.body.total,
               "data": res.body.data
           };
       }
       ,response: {statusCode: 200}
       ,cols: [[
           {field: 'userId', title: '代理ID'}
           ,{field: 'name', title: '用户名称',templet:function (record){
               if(record.user){
                   return record.user.name;
               }else{
                   return '未知用户信息';
               }
           }}
           ,{field: 'phone', title: '用户手机号',templet:function (record){
               if(record.user){
                   return record.user.phone;
               }else{
                   return '--';
               }
           }}
           ,{field: 'businessTypeName', title: '业务类型'}
           ,{field: 'incomeRatio', title: '分成比例',templet:function (record){
				if(!record.incomeRatio){
					record.incomeRatio = 0;
				}
				return record.incomeRatio + '%';
		   }}
           ,{field: 'updateDate', title: '修改时间'}
           ,{field: 'createDate', title: '创建时间'}
       ]]
       ,page: true
       ,height: 'full-220'
       ,text: '对不起，加载出现异常！'
   });
   
   element.on('tab(tab-info)', function (data) {
           if(data.index == 0) {
               table.reload('LAY-table')
           }else if(data.index == 1) {
               table.reload('LAY-table-profit-cfg')
           }
       });

    var active = { 
		
	 };

    $('.layui-btn.LAY-btn-fun').on('click', function(){
        var type = $(this).data('type');
        active[type] ? active[type].call(this) : '';
    });

    table.on('tool(LAY-table)', function(obj){
        var type = obj.event ;
        active[type] ? active[type].call(this,obj) : '';
    });

    exports('agent_referrer_info', {})
});